public with sharing class SetNationalAttendance {
   public String strTest{get;set;}
    public String idStr{   
         get{       
               return System.currentPageReference().getParameters().get('id');    
            }         
           set;}
    public List<NationalAttendee__c> AttendeeList{
    get
    {
        if(AttendeeList==null)
            AttendeeList=new List<NationalAttendee__c>();
        return AttendeeList;
    }
    set;}
    
    public List<NationalAttendee__c> getAttendee
    {
        get{
            if(AttendeeList!=null)
            {
                AttendeeList.clear();
            }
           for(NationalAttendee__c att:[select id,HCP__c,Hospital2__c,HCPDepartment__c,HCPadministrativetitle__c,IsAttended__c 
                                        from NationalAttendee__c where CityNameLists__c=:idStr])
                    {
               AttendeeList.add(att);
           }
           return AttendeeList;
       }
       set;
    }
    
    public PageReference Save()
    {
        update AttendeeList;
                     
         pageReference pr = new pageReference('/'+ idStr); 
         pr.setredirect(true);        
         return pr;  
     }
     
    static testMethod void SetNationalAttendanceTest()
    {
         Profile p  = [select id from profile where name=: 'System Administrator'];   //id =:UserInfo.getProfileId()]; 
         User u3 =new User (alias = 'new', email = 'shlia@isoftstone.com', emailencodingkey='UTF-8', lastname = 'Testing', languagelocalekey = 'en_US', localesidkey='en_US', profileid = p.id, timezonesidkey = 'Asia/Shanghai', username='new3@testorg1.com');
        insert u3;
         User u2 =new User (alias = 'new', email = 'shlia@isoftstone.com', emailencodingkey='UTF-8', lastname = 'Testing', languagelocalekey = 'en_US', localesidkey='en_US', profileid = p.id, timezonesidkey = 'Asia/Shanghai', username='new@testorg1.com',managerid=u3.id);
        insert u2;
        User u1 =new User (alias = 'standt', email = 'shlia@isoftstone.com', emailencodingkey='UTF-8', lastname = 'Testing', languagelocalekey = 'en_US', localesidkey='en_US', profileid = p.id, timezonesidkey = 'Asia/Shanghai', username='standarduser@testorg1.com',managerid=u2.id);
        insert u1; 
        
        NationalAttendee__c nat = new NationalAttendee__c();
        
        HCPEducation__c hcpe = new HCPEducation__c();
        hcpe.date__c = date.Today().addDays(20);
        hcpe.place__c = 'a';
        insert hcpe; 

        Hospital__c hos = new Hospital__c();
        hos.Name = 'aaaaaaaa';
        hos.Nickname__c = 'aaaaaaaaaaa';
        insert hos;     
           
        HCP__c hcp= new HCP__c();
        hcp.class1__c = '全国学术带头人(NKOL)';
        hcp.Hospital__c = hos.Id;
        insert hcp; 
        
        
        recordtype rgrt=[select id from recordtype where sobjecttype=:'place__c' and name=:'region'];
           Place__c rgl=new  Place__c();
           rgl.name='华北区';
           rgl.recordtypeid=rgrt.id;
           rgl.ownerid = u1.id;
           insert rgl;
        
           RegionNameList__c rnl=new RegionNameList__c(ownerid = u1.id,HCPEducation__c=hcpe.id,name='华北区名单',region__c=rgl.id,TargetNo__c=20);
           insert rnl;
           
           citynamelist__c cnl=new citynamelist__c(ownerid = u1.id,RegionNameList__c=rnl.id,name='上海',TargetNo__c=20);
           insert cnl;
                      
    System.runAs(u1) {          
        JoinPeople__c jp = new JoinPeople__c ();
           jp.CityNameList__c = cnl.Id;
           jp.User__c = u2.Id;
           insert jp;
       System.runAs(u2) {    
        nat.Hospital__c = hos.Id;
        nat.HCPEducation__c = hcpe.Id;
        nat.HCP__c = hcp.Id;
        
        test.setCurrentPageReference(Page.SearchAttendanceUser);
        System.currentPageReference().getParameters().put('id', hcpe.Id); 
                
        insert nat;    
    
        SetNationalAttendance testCase = new SetNationalAttendance();
     
        testCase.Save();
        System.assert(testCase.getAttendee != null);
        }
        }
    
    }     
     
}